<style type="text/css">
	.user_info_box_green .field{ width:100%; margin:10px 0; padding-right:0; overflow:hidden; float:none; }
	.user_info_box_green .field label{ width:140px; padding-right:5px; }
	.ke-toolbar td { padding:0}
	.user_info_item span.w125{ display:inline-block;}
	.ui-form-table {margin-top: 20px;text-align: left;border-bottom: 1px solid #e0e0e0;}
	.ui-form-table tr {height: 50px;}
	.ui-form-table th, .ui-form-table td {border-top: 1px solid #e0e0e0;font-weight: 500;font-style: normal;border-spacing: 2px;}
	.Ddescription{ display:block; width:650px; overflow:hidden;}
	.Ddescription img{ max-width:650px;}
</style>

<div class="blank"></div>
<div class="blank5"></div>
<form action="{url x="index" r="borrow#savedeal"}" method="post" id="J_save_deal_form" style="margin:0 10px;">
	
	<div class="user_info_box_green p10 clearfix">
		<div class="field">
			<label>借款标题：</label>
			<span class="lh30">
			{$deal_quota.name}
			</span>
		</div>
		<div class="blank0"></div>
		<div class="field">
			<label>借款用途：</label> 
			<span class="lh30">
			{$deal_quota.type_name}
			</span>
		</div>	
		<div class="blank0"></div>	
		<div class="field">
			<label>借款金额：</label> 
			<span class="lh30"> 
				<input type="text" value="{$deal.borrow_amount}" name="borrowamount" id="borrowamount" class="f-input">
				&nbsp;&nbsp;元
				（借款金额<?php echo number_format(app_conf("MIN_BORROW_QUOTA")); ?>起，需为50的倍数，我的可用额度：
				<span style="font-size: 14px;" class="f_red">
					{$can_borrow_amount}
				</span>） 
			</span>
		</div>
		
		<div class="blank0"></div>
		<div class="field">
			<label>借款期限：</label> 
			<span class="lh30"> 
				<input type="text" value="" name="repay_time" id="repay_time" class="f-input" style="width:60px">
				&nbsp;&nbsp;个月
			</span>
		</div>
		<div class="blank0"></div>
		<div class="field">
			<label>年利率：</label> 
			<span class="lh30"> 
				{$deal_quota.rate} %
			</span>
		</div>
		<div class="blank0"></div>
		<div class="field">
			<label>还款周期：</label> <span class="lh30">按月还款</span>
		</div>
		<div class="blank0"></div>
		<div class="field">
			<label>还款方式：</label> 
			<span class="lh30">
			{function name="loantypename" v=$deal_quota.loantype}
		</div>
		
		<div class="blank0"></div>
		<div class="field">
			<label>筹标期限：</label>
			<span class="lh30">
				{$deal_quota.enddate}&nbsp;天
			</span>
		</div>
		<div class="blank0"></div>
		<div class="field" id="monthRepayMoney_box">
			<label>每月还本息：</label> 
			<span style="color: red;" id="monthRepayMoney" class="lh30">￥0.00</span>
		</div>
		<div class="blank0"></div>
		<div class="field" id="LastRepayMoney_box" style="display:none;">
			<label>到期需还本金：</label>
			<span style="color: red;" id="LastRepayMoney" class="lh30">￥0.00</span>
		</div>
		<div class="blank0"></div>
		<div class="field" id="monthRepayManage_box">
			<label>每月交借款管理费：</label> 
			<span style="color: red;" id="managerFee" class="lh30">￥0.00</span>
		</div>
		<div class="blank0"></div>
		<div class="field">
			<label>成交服务费：</label> 
			<div class="f_l" style="width:650px">
				<span  class="lh30">由{function name="app_conf" v="SITE_TITLE"}平台收取</span>
				<table width="100%" class="table ui-form-table" id="ratetable">
	                <thead>
		                <tr>
		                    <th>信用等级</th>
							{foreach from="$level_list.list" item="level"}
		                    <th class="tc"><img src="{$TMPL}/images/{$level.name}.png" width="30" /></th>
							{/foreach}
		                </tr>
	                </thead>
	                <tbody>
		                <tr>
		                    <td>服务费率</td>
		                    {foreach from="$level_list.list" item="level"}
		                    <td class="tc">{$level.services_fee}%</td>
							{/foreach}
		                </tr>
		                <tr>
		                    <td>服务费</td>
							 {foreach from="$level_list.list" item="level"}
		                    <td class="tc J_fee" fee="{$level.services_fee}"></td>
							{/foreach}
		                </tr>
	                </tbody>
	            </table>
			</div>
		</div>
		<div class="blank0"></div>
		
		
		<div class="field" style="clear: both;">
			<label>借款描述：</label> 
			<div id="Ddescription" class="f_l lh30">
				{$deal_quota.description}
			</div>
		</div>
		
		
		<div class="field">
			<label>展示资料：</label> 
			<div class="f_l">
				<div style="width:719px;">
				 				 
		    	 {if $user_view_info}
		    	 	 {foreach from =$user_view_info item="img_item" key=key}
						<p style="float:left">
						<input  style=" margin-top: 12px; display:none "  {if $img_item.is_selected eq 1} checked="checked" {/if}  type="checkbox" name="file_key[]" value="{$img_item.key}">
						<a href='{$img_item.img}' target="_blank" title="{$img_item.name}"><img width="35" height="35" style="float:left; border:#ccc solid 1px; margin-left:5px;" id="{$img_item.name}" src="{$img_item.img}"></a>
						</p>
					 {/foreach}
		    	 {/if}
		            
		    	 </div>
		    	
			</div>
		</div>
		
	</div>
	
	
	<div class="user_info_box_green p10 clearfix">
		<div class="field" style="clear: both;">
			<label>&nbsp;</label>
			<span> 
			<input type="checkbox" checked="" id="treaty1"> &nbsp;我同意{function name="app_conf" v="SHOP_TITLE"}<a href="{url x="index" r="help" p="id=$agreement"}" target="_blank" class="f_blue">《借款协议》</a>
			</span> 
		</div>
	</div>
	
	<div class="user_info_box_green p10 clearfix">
		<div class="field" style="clear: both;">
			<label>&nbsp;</label>
			<input type="button" id="publishBnt" class="mbtn topublish" value="" onclick="saveAndPreview('publish');">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
			<input type="submit" id="previewBtn" class="mbtn preview" value="" onclick="$('#J_save_deal_form').attr('target','_blank');$('#J_save_deal_form').attr('action','{url x="index" r="deal#preview" p="quota=1"}');">
		</div>
	</div>
</form>
<script type="text/javascript">
	jQuery(function(){
		
		$("#J_save_deal_form").submit(function(){
			if(!checkSaveDealForm(false)){
				return false;
			}
			return true;
		});
		
		
		$("#borrowamount,#repay_time").bind("blur keyup change",function(){
			CalculateDeal();
		});
		CalculateDeal();
	});
	
	function checkSaveDealForm(){
		
		if($.trim($('#borrowamount').val())=="" || parseInt($('#borrowamount').val()) < {function name="app_conf" v="MIN_BORROW_QUOTA"} || parseInt($('#borrowamount').val()) > {$can_borrow_amount} || parseInt($('#borrowamount').val())%50 !=0 ){
			$.showErr("请正确输入借款金额",function(){
				$("#J_save_deal_form #borrowamount").focus();
			});
			return false;
		}
		
		if($.trim($("#J_save_deal_form input[name='repay_time']").val())=="" || parseInt($("#J_save_deal_form input[name='repay_time']").val())==0){
			$.showErr("请输入正确的借款期限",function(){
				$("#J_save_deal_form input[name='repay_time']").focus();
			});
			return false;
		}
		
		if($("#J_save_deal_form #treaty1:checked").length==0){
			$.showErr("请同意我们的借款协议",function(){
				$("#J_save_deal_form #treaty1").focus();
			});
			return false;
		}
		return true;
	}
	
	function saveAndPreview(act){
		if(!checkSaveDealForm()){
			return false;
		}
		var url = '{url x="index" r="borrow#savedealquota"}';
		if(!confirm("确定发布吗？发布后将无法修改！")){
			return false;
		}
		$("#J_save_deal_form").attr("action",url);
		$("#J_save_deal_form").submit();
		
	}
	
	function CalculateDeal(){
		var apr = {$deal_quota.rate};
		var repaytime = parseInt($("#repay_time").val());
		var repaytime_type =  1;
		if(parseFloat($.trim($("#borrowamount").val())) >0 && parseFloat(apr) > 0){
			var amo = parseFloat($.trim($("#borrowamount").val()));
			var inter =  parseFloat(apr);
			var inters=inter * 100 / 12 /(100 * 100);
			var loantype ={$deal_quota.loantype};
			var value = 0;
			if(parseInt(loantype)==1){
				value = amo*inters;
				$("#LastRepayMoney").html("￥"+formatNum(amo));
			}
			else if(parseInt(loantype)==2){
				if(repaytime_type==1)
					value = amo*inters * repaytime;
				else
					value = amo*inters;
					
				$("#LastRepayMoney").html("￥"+formatNum(amo));
			}
			else if(parseInt(loantype)==0){
	        	value=amo*(inters * Math.pow(1+inters, repaytime)) / (Math.pow(1+inters, repaytime)-1);
	        }
			$("#monthRepayMoney").html("￥"+formatNum(value));
			if(parseInt(loantype)==2){
				if(repaytime_type==1)
					$("#managerFee").html("￥"+formatNum(amo * repaytime * {function name="app_conf" v="MANAGE_FEE"}/100));
				else
					$("#managerFee").html("￥"+formatNum(amo * {function name="app_conf" v="MANAGE_FEE"}/100));
			}
			else{
				$("#managerFee").html("￥"+formatNum(amo * {function name="app_conf" v="MANAGE_FEE"}/100));
			}
			
			$(".J_fee").each(function(){
				var fee = parseFloat($(this).attr("fee"));
				$(this).html(formatNum(fee * amo / 100));
			});
		}
	}
	
	
</script>